package com.augrain.microframework;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 配置
 *
 * @author biaoy
 * @since 2024/12/28
 */
public class AllStarterConfiguration implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        Map<String, Object> attributes = metadata.getAnnotationAttributes(EnableAllStarter.class.getName());
        if (attributes == null) {
            return new String[0];
        }

        List<String> imports = new ArrayList<>();
        boolean enableLimit = Boolean.parseBoolean(attributes.get("limitStarter").toString());
        if (enableLimit) {
            imports.add("com.augrain.microframework.limit.RateLimitAutoConfiguration");
        }
        return imports.toArray(new String[0]);
    }
}
